/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.model;
import com.db.SqlManager;
import com.exception.DataException;
import com.javabeans.Rol;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
/**
 *
 * @author Administrador
 */
public class AdminRol implements RolManager{
    private Connection c;

    public AdminRol(Connection c){
        this.c = c;
    }
    
    /*==============================================================*/
    /* METODO QUE LISTA ROLES DE LA BD                              */
    /*==============================================================*/
    @Override
    public List<Rol> getRoles() throws DataException{
        List<Rol> roles = new ArrayList<Rol>();
        ResultSet rs = null;
        PreparedStatement preSt = null;
        String query = "";
        try{
            query = "SELECT IDROL, NOMBRE";
            query += " FROM ROL WHERE IDROL = 1";            
            preSt = c.prepareStatement(query);
            rs = preSt.executeQuery();
            while(rs.next()){
                Rol r = new Rol();
                r.setIdRol(rs.getInt("IDROL"));
                r.setNombre(rs.getString("NOMBRE"));
                roles.add(r);
            }
        }catch(SQLException e){
            throw new DataException(" AdminRol -> getRoles() e = "+e.getMessage());
        }finally{
            SqlManager.closeRs(rs);
            SqlManager.closePreSt(preSt);
        }
        
        return roles;
    }
}